package view.listener;

import model.Constants;

import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Text;

import control.Storage;
import control.Util;

public class StartButtonListener extends SelectionAdapter {

	@Override
	public void widgetSelected(SelectionEvent arg0) {

		Control children[] = arg0.display.getActiveShell().getChildren();

		for (int i = 0; i < children.length; i++) {

			if (children[i] instanceof Text) {
				Text text = (Text) children[i];
				if (i == 1) {
					if (Util.validateInput(text.getText())) {
						Storage.getInstance().setPlayerName(text.getText());
					} else {
						Storage.getInstance().setPlayerName(Constants.PLAYER);
					}

				} else {
					if (Util.validateInput(text.getText())) {
						Storage.getInstance().setEnemyName(text.getText());
					} else {
						Storage.getInstance().setEnemyName(Constants.ENEMY);
					}
				}
			}
		}
		Storage.getInstance().setConfigured(true);
		arg0.display.getActiveShell().dispose();

	}

}
